package com.wrupple.muba.catalogs.client.widgets.fields.cells;

import com.google.gwt.dom.client.Element;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;
import com.wrupple.muba.catalogs.client.activity.process.task.CatalogInteractionState.Mode;
import com.wrupple.muba.common.shared.Process;
import com.wrupple.muba.common.shared.State.ProcessManager;
import com.wrupple.vegetate.domain.FieldDescriptor;

public class RichTextCell extends ProcessDelegatingEditableField<String> {

	public RichTextCell(EventBus bus,ProcessManager pm,FieldDescriptor d,Mode mode, Process<String, String> nestedProcess, String processName) {
		super(bus, pm, nestedProcess,processName,d, mode);
	}

	@Override
	protected void renderAsInput(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb,
			FieldData<String> viewData) {
		sb.appendEscaped("...");
	}

	@Override
	protected void renderReadOnly(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb,
			FieldData<String> viewData) {
		sb.append(SimpleSafeHtmlRenderer.getInstance().render(value));
	}

	@Override
	protected String getCurrentInputValue(Element parent,  boolean isEditing) {
		return parent.getInnerHTML();
	}

	@Override
	protected void onValueWillCommit(Element parent,
			com.wrupple.muba.catalogs.client.widgets.fields.cells.AbstractEditableField.FieldData<String> viewData) {
	}

	@Override
	protected void onWillEnterEditMode(Element parent,
			com.wrupple.muba.catalogs.client.widgets.fields.cells.AbstractEditableField.FieldData<String> viewData) {
	}

}
